<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base],
        components: {
             SelectImageRadio: async () =>
            Vue.extend(
                await Vue.prototype.$vFN.Components.Base.SelectImageRadio()
            ),
        },
        props: {
            // 一级栏目id
            form: {
                type: Object,
                default: null,
            },
            // 字数限制
            size: {
                type: Number,
                default: 0,
            },
            appWindow: {
                type: Object,
                default: null,
            },

        },
        computed: {

        },

        data() {

            return {
                typeList: [{
                    label: 'click',
                    text: '发送消息',
                }, {
                    label: 'view',
                    text: '跳转链接',
                }, {
                    label: 'miniprogram',
                    text: '跳转小程序',
                }],


                msgTypeList: [{
                        icon: "el-icon-document",
                        label: 'text',
                        text: '文本',
                    },
                    {
                        icon: "el-icon-picture-outline-round",
                        label: 'image',
                        text: '图片'
                    },
                    {
                        icon: "el-icon-microphone",
                        label: 'voice',
                        text: '语音'
                    },
                    {
                        icon: "el-icon-video-camera",
                        label: 'video',
                        text: '视频'
                    },
                    {
                        icon: "el-icon-postcard",
                        label: 'news',
                        text: '图文'
                    },
                    {
                        icon: "el-icon-chat-line-round",
                        label: 'keyword',
                        text: '关键词'
                    },
                ],

                form: null
            };
        },
        methods: {
            delItem(){
                this.$emit("delItem")
            },
            selectImage() {
                this.$vFN.Directives.SelectResourcesImage({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.form._content.image = res.all.obj[0]
                    },
                });
            },
            selectVideo() {
                this.$vFN.Directives.SelectResourcesVideo({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.form._content.video = res.all.obj[0]
                    },
                });
            },
            selectVoice() {
                this.$vFN.Directives.SelectResourcesAudio({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        this.form._content.voice = res.all.obj[0]
                    },
                });
            },
            selectTuwen() {
                this.$vFN.Directives.SelectResourcesWxTuwen({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        console.error(res.all)
                        this.form._content.news = res.all.obj[0]
                    },
                });
            },
            SelectWxReplyKeyword() {
                this.$vFN.Directives.SelectWxReplyKeyword({
                    appWindow: this.appWindow,
                    count: 1,
                    mode: "wx",
                    onSuccess: (res) => {
                        console.error(res)
                        this.form._content.keyword = res.data
                    },
                });
            },
        },
        mounted() {},
        beforeCreate() {},
        watch: {
            "form": {
                handler(newName, oldName) {
                    if (!newName) {
                        return
                    }
                    if (!newName.name) {
                        return
                    }
                    if (this.$vFN.Utils.getByteLen(newName.name) > this.size * 2) {
                        newName.name = newName.name.slice(0, newName.name.length - 1)
                    }

                },
                immediate: true,
                deep: true,
            },
        },
    };
</script>
